namespace NTrace
{
  using System;
  using System.Collections.Generic;
  using ICSharpCode.NRefactory;

  public class PreprocessorContext
  {
    private readonly Environment environment;
    private readonly String codeFile;
    private readonly IList<String> lines;
    private readonly TargetLanguage language;
    private readonly TraceMessageFile traceMessageFile;

    internal PreprocessorContext(Environment environment, String codeFile, SupportedLanguage language)
    {
      this.environment = environment;
      this.codeFile = codeFile;
      this.lines = new List<String>();
      this.language = PreprocessorContext.CreateTargetLanguage(language);
      this.traceMessageFile = new TraceMessageFile(this);
    }

    public Environment Environment
    {
      get
      {
        return this.environment;
      }
    }

    public String CodeFile
    {
      get
      {
        return this.codeFile;
      }
    }

    public IList<String> Lines
    {
      get
      {
        return this.lines;
      }
    }

    public TargetLanguage Language
    {
      get
      {
        return this.language;
      }
    }

    public TraceMessageFile TraceMessageFile
    {
      get
      {
        return this.traceMessageFile;
      }
    }

    private static TargetLanguage CreateTargetLanguage(SupportedLanguage language)
    {
      TargetLanguage output = null;

      switch (language)
      {
        case SupportedLanguage.CSharp:
          output = new CSharpLanguage();
          break;
        case SupportedLanguage.VBNet:
          output = new VBNetLanguage();
          break;
        default:
          // Unsupported language
          throw new PreprocessorException(PreprocessorErrors.InvalidFileExtension, "Unsupported language");
      }

      return output;
    }
  }
}
